package com.dragon.connector.imServer.initializer;

import com.dragon.connector.imServer.handler.ImExceptionHandler;
import com.dragon.connector.imServer.handler.InformationNotification;
import com.dragon.connector.imServer.handler.ReceiveMessageHandler;
import com.dragon.protoJo.codec.ProtobufDecoder;
import com.dragon.protoJo.codec.ProtobufEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.springframework.stereotype.Service;


@Service
public class TcpScoketInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline
                // proto二进制数据解码
                .addLast("deCoder",new ProtobufDecoder())
//                // proto数据编码
                .addLast("enCoder",new ProtobufEncoder())
//                .addLast("websocketEnCoder",new WebsocketProtobufEncoder())
//                .addLast(new HeartBeatServerHandler())
                .addLast("ReceiveMessage",new ReceiveMessageHandler())
                .addLast("information",new InformationNotification())
                .addLast("ImExceptionHandler",new ImExceptionHandler());
    }
}
